<template>
    <div class="navbarContainer">
        <el-form ref="form"
                :model="form"
                label-width="140px"
                @submit.native.prevent
                >
            <el-row>
                <el-col :span="10" :xs="18" :sm="18" :md="18" :lg="18" :xl="18">
                    <el-form-item >
                        <template slot="label">
                            {{M2('执行结果')}}:
                        </template>
                        <el-radio-group size="mini"  v-model="form.executionResult">
                            <el-radio-button @click.native="clickRadioSearch('executionResult',item,$event)" v-for="item in serverList" :key="item.label" :label="item.label">{{ item.name }}</el-radio-button>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6">
                    <el-form-item label-width="10px">
                        <div class="searchBox">
                            <el-select v-model="form.searchType"
                                size='mini'
                                class="timeBox"  
                                placeholder="选择事件类型"     
                                style="width:100px;flex-shrink: 0;" 
                                >
                                <el-option 
                                    v-for="(item) in searchTypeList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value" 
                                >
                                </el-option>
                            </el-select>
                            <el-input :placeholder="M2('请输入查询条件')"
                                v-model="putSearch"
                                size='mini'
                                class="input-with-select"
                                clearable
                                @change="searchSomething"
                                @keyup.enter.native="searchSomething"
                                >
                            </el-input>
                            <el-button type="primary" @click="searchSomething">{{M2('搜索')}}</el-button>
                            <el-checkbox  class="search-check" v-model="form.selectCheck" :label="1">{{M2('在筛选条件中搜索')}}</el-checkbox>
                            <span class="more-search" @click="clickSearchMore()"  v-track="{triggerType:'click',currentUrl: $route.path,behavior:'批量查询'}">
                                {{M2('批量查询')}}
                            </span>
                        </div>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="10" :xs="20" :sm="24" :md="24" :lg="24" :xl="24">
                    <el-form-item >
                        <template slot="label">
                            {{M2('所属系统')}}:
                        </template>
                        <el-radio-group size="mini"  v-model="form.owningSystem">
                            <el-radio-button @click.native="clickRadioSearch('owningSystem',null,$event),changeS()" :label="null">{{ M2('全部') }}</el-radio-button>
                            <el-radio-button @click.native="clickRadioSearch('owningSystem',item.sysKey,$event),changeOwningSystem(index)" v-for="(item,index) in owningSystemList" :key="index + item.sysKey" :label="item.sysKey">{{ item.sysKey }}</el-radio-button>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
             </el-row>
             <el-row>
                <el-col :span="10" :xs="20" :sm="24" :md="24" :lg="24" :xl="24">
                    <el-form-item v-if="form.owningSystem !== null">
                        <template slot="label">
                            {{M2('事件类型')}}:
                        </template>
                        <el-select v-model="form.eventType"
                            size='mini'
                            class="timeBox"  
                            placeholder="选择事件类型"      
                            >
                            <el-option 
                                v-for="(item,index) in typeList"
                                :key="Math.random() + index"
                                :label="item.eventTypeValue"
                                :value="item.eventType" 
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
             </el-row>
             <el-row>
                <el-col :span="10" :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                    <el-form-item>
                        <template slot="label">
                            {{M2('事件时间')}}:
                        </template>
                        <div style="display:flex;align-items:center">
                            <el-radio-group size="mini"  v-model="form.timeEnum">
                                <el-radio-button @click.native="clickRadioSearch('timeEnum',item,$event)" v-for="item in timeTypeList" :key="item.label" :label="item.label">
                                    {{ item.name }}
                                </el-radio-button>
                            </el-radio-group>
                            <el-date-picker 
                                v-model="form.timeValue2"
                                type="daterange"
                                align="right"
                                unlink-panels
                                :range-separator="M2('至')"
                                :start-placeholder="M2('开始日期')"
                                :end-placeholder="M2('结束日期')"
                                :picker-options="pickerOptions"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                size='mini'
                            >
                            </el-date-picker>    
                        </div>
                            
                    </el-form-item>
                </el-col>
             </el-row>
        </el-form>
        <searchMoreDialog ref="searchMoreDialog" @searchMorething='searchMorething'></searchMoreDialog>
    </div>
</template>
<script>
import { trim } from '@/utils/tools.js';
import { getSys } from '@/api/user.js'
export default {
    name: 'releaseManagementNaver',
    components:{
        searchMoreDialog:() => import('@/components/common/searchMoreDialog'),
    },
    data () {
        return {
            putSearch:null,
            owningSystemList:[],
            searchTypeList:[
                {
                    value:null,
                    label:'综合搜索'
                },
                {
                    value:1,
                    label:'客户端IP'
                },
                {
                    value:2,
                    label:'操作账号'
                },
            
            ],
            typeList:[],
            serverList:[
                {
                    name:'全部',
                    label:null,
                },
                {
                    name:'成功',
                    label:0
                },
                {
                    name:'失败',
                    label:1
                },
            ],
            timeTypeList:[
                 {
                    name:'全部',
                    label:500,
                },
                {
                    name:'今天',
                    label:501
                },
                {
                    name:'3天内',
                    label:502
                },
                {
                    name:'7天内',
                    label:503
                },
                {
                    name:'15天内',
                    label:504
                },
                {
                    name:'30天内',
                    label:505
                },
            ],
            pickerOptions: {
                shortcuts: [
                {
                    text: '最近三天',
                    onClick (picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
                    picker.$emit('pick', [start, end]);
                    }
                },
                {
                    text: '最近一周',
                    onClick (picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                    }
                },
                {
                    text: '最近十五天',
                    onClick (picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
                    picker.$emit('pick', [start, end]);
                    }
                },
                {
                    text: '最近一个月',
                    onClick (picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                    picker.$emit('pick', [start, end]);
                    }
                }]
            },
            form: {
                search: null, //搜索(供应商、开发ID、sku别名、sku、申请单号)
                serviceCode:null,
                type:null,
                programType:null,
                timeEnum:500,
                executionResult:null,
                owningSystem:null,
                searchType:null,
            },
        }
    },
    watch:{
        form:{
            handler:function(val){
                this.tableParams = val
                this.$emit('putTableList',this.tableParams)          
            },
            deep:true
        },
    },
    created() {
    },
    mounted(){
        this.$nextTick(res => {
            if(this.$route.query.search){
                this.putSearch = this.$route.query.search
            }
        })
        this.addTitleLable()
        this.init()
    },
    methods: {
        changeS(){
            this.typeList = []
        },
        changeOwningSystem(i){
            this.$set(this.form,'eventType',null)
            this.typeList = this.owningSystemList[i].eventTypes || []
        },
        addTitleLable(){
            document.querySelectorAll('.navbarContainer .el-form-item__label').forEach(item => {
                if(!item.getAttribute('title')){
                    item.setAttribute('title',item.innerHTML)
                }                
            })
        },
        init() {
            getSys().then(res => {
                this.owningSystemList = res.data
            })
            
        },
        searchMorething(list){
            this.searchMore = { 
                parametersType:list.parametersType,
                parameters:list.parameters,
            }
            this.$emit('putTableList',this.searchMore)
        },
        clickSearchMore() {
            this.$refs.searchMoreDialog.openDialog()
        },
        clickRadioSearch(name,value,el) {
            if (el.target.tagName === 'INPUT') return
            this.$set(this.form,name,value)
            this.$set(this.form,'search1',false)
            this.$set(this.form,'almorlist',Math.random())
        },
        searchSomething(){
            this.$set(this.form,'search',trim(this.putSearch))
            this.$set(this.form,'search1',true)
            this.$set(this.form,'almorlist',Math.random())
        },
    
    }
}
</script>

<style  lang="scss" scoped>
::v-deep.checkbox-status {
    display: inline-block;
    .el-checkbox.is-bordered {
        margin-right: 0px;
        margin-left: 5px;
        height: 25px;
        top: 2px;
        padding: 2px 3px;
    }
}
.navbarContainer {
    padding: 5px;
    background-color: #ffffff;
    ::v-deep .el-form-item__label {
        color: #3366cc !important;
        font-weight: bold; 
        line-height: 30px; 
        overflow: hidden;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding-left: 10px;
    }
    ::v-deep .el-form-item__content{
        font-size: 12px !important;
        line-height: 30px;
    }
    ::v-deep .el-form-item {
        margin-bottom: 0px;
    }
    ::v-deep .el-radio-button{
        line-height: 2;
        margin: 3px 4px;
        .el-radio-button__inner {
            padding: 5px 10px;
            color: #333 ;
            border-radius: 2px;
            border: 1px solid #DCDFE6;
            border-left: 1px solid #DCDFE6;
            &:hover {
                border: 1px solid #3366cc;
                border-left: 1px solid #3366cc;
                color: #3366cc;
            }
        }  
    }
    ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
        box-shadow: 0px 0 0 0 #3366cc;
        color: #ffff;
    }
   
    ::v-deep .success-radio {
        border: 1px solid #ccc;
        display: inline-block;
        margin-right: 10px;
        height: 25px;
        line-height: 25px;
        position: relative;
        top: 5px;
        padding-right: 10px;
        background: #e8f0f7;
        .el-radio__input {
            border-right:1px solid #ccc;
            line-height: 23px;
        }
    }
}
.searchBox{
    display: flex;
    .el-button{
        height: 28px;
        margin-top: 1px;
        line-height: 3px;
        padding: 12px 12px;
        font-size: 12px;
        margin-right: 10px;
    }
    .more-search {
        color: #3366cc;
        position: absolute;
        right: 10px;
        bottom: -25px;
        cursor: pointer;
        z-index: 111;
    }
    .search-check {
        position: absolute;
        bottom:-25px;
        left: 0;
    }
}
/* 父级不可点击 */
::v-deep .disabled-el-group {
        .el-radio-button__inner {
            cursor: default !important;
        }  
    }
    ::v-deep.navbarContainer .el-radio-button__orig-radio:checked + .el-radio-button__inner {
        background-color: #3366cc;
    }
</style>
<style>
    .is-active .el-radio-button__inner {
        color: #fff !important;
    }
    .popper-tooltip {
        max-width: 80%;
         transform:translate(0,-10px);
        /* top: 59px !important; */
        left: 160px !important;
        min-width: 600px;
        padding: 2px 10px;
        border: 1px solid #3366cc !important;
    }
    .popper-tooltip .el-radio-button {
        margin-bottom:3px;
    }
    .popper-tooltip .el-radio-button__inner {
        border-left: 1px solid #DCDFE6 !important;
    }
    .popper-tooltip .popper__arrow {
        display: none;
       
    }
    .el-radio-button__orig-radio:checked+.el-radio-button__inner {
        border-left: none !important;
    }
    .tooltip-text{
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: bold;
        padding: 5px 0px;
        margin-bottom: 3px;
        border: 1px solid #6D92B8;
        border-radius: 4px;
        background-color: #E8F0F7;
     }
</style>